package com.fjec.common.okhttp;

import lombok.extern.slf4j.Slf4j;
import okhttp3.Request;
import okhttp3.Response;

import java.io.IOException;

@Slf4j
public class OkHttpDemo {

    public static void main(String[] args) {
        getWxInfo();
        // post();
        // postJson();
        // uploadFile();
    }

    public static void get() {
        // 构建请求
        Request request = new Request.Builder().get().url("http://www.baidu.com").build();
        // 同步调用
        OkHttp okHttp = new OkHttp();
        okHttp.init();
        try {
            okHttp.doRequest(request, new HttpCallBack<String>() {
                @Override
                public String process(Response response) throws IOException {
                    log.debug(new String(response.body().bytes()));
                    return null;
                }
            });
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    public static void getWxInfo() {
        String url = "https://api.weixin.qq.com/cgi-bin/user/info?access_token=%s&openid=%s";
        String accessToken = "39_jJpa0FyOMRrnHhdawD6ovlevQGzqn0diYtiNqcq81z26_6mfXjCAfZ9g3mr6GKA5XFiR8davBP2TrOBT4PAWfM4wHcfPqupm_WTHOrbyBNRkQAwj6iePuOqnsSIPWEupoLN05Trpk3WvEknNKHUeAAAYVI";
        String openId = "o0rHO4rj3lUJ21QQ_UAFjWjDsKdU";

        OkHttp okHttp = new OkHttp();
        okHttp.init();

        String result = okHttp.get(String.format(url, accessToken, openId));
        System.out.println(result);
    }

}
